package org.snusmumr.android.media.tools;

import org.snusmumr.android.media.util.Utils;

import android.util.Log;

public class ModelLabel {
	private static final int DEFAULT_COLOR = 0;
	private static final String TAG = ModelLabel.class.getSimpleName();
	
	private String 	label;
	private int 	color;
	
	/**
	 * Creates model instance for label.
	 * 
	 * @param nameCode
	 *            is assembled from <code>label</code>@ <code>color</code>,
	 *            where "@" is a separator
	 * 
	 *            If no separator passed, default color is set
	 */
	public ModelLabel(String nameCode) {
		if(! Utils.isEmpty(nameCode)) {
			String[] tmp = nameCode.split("@");
			label = tmp[0].trim();
			if(tmp.length > 1) {
				try {
					color = Integer.parseInt(tmp[1].trim());
				} catch (NumberFormatException e) {
					Log.e(TAG, "Cannot parse label color", e);
					color = DEFAULT_COLOR;
				}
			} else
				color = DEFAULT_COLOR;
		}
	}
	
	public String getLabel() {
		return label;
	}
	
	public int getColor() {
		return color;
	}
}
